﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace YXShop.Web.membercenter
{
    public partial class membershopcart : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!this.Page.IsPostBack)
            {
                int id = ChangeHope.WebPage.PageRequest.GetQueryInt("id");
                if (id > 0)
                {
                    Delete(id);
                }
                GetList();
            }
        }

        private void GetList()
        {
            YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            YXShop.BLL.Order.ShoppingCard data = new YXShop.BLL.Order.ShoppingCard();
            ChangeHope.DataBase.DataByPage dataPage = data.GetProfilesList("");
            //第一步先添加表头
            table.AddHeadCol("10%", "序号");
            table.AddHeadCol("50%", "购者名称");
            table.AddHeadCol("25%", "购物时间");
            table.AddHeadCol("15%", "操作");
            table.AddRow();
            //添加表的内容
            if (dataPage.DataReader != null)
            {
                int curpage = ChangeHope.WebPage.PageRequest.GetInt("pageindex");
                if (curpage < 0)
                {
                    curpage = 1;
                }
                int count = 0;
                while (dataPage.DataReader.Read())
                {
                    count++;
                    string No = (15 * (curpage - 1) + count).ToString();
                    table.AddCol(No);
                    table.AddCol(string.Format("{0}", dataPage.DataReader["username"].ToString()));
                    table.AddCol(dataPage.DataReader["lastupdateddate"].ToString());
                    table.AddCol(string.Format("<a href='#' onclick='Del({0})'>删除</a>", dataPage.DataReader["username"].ToString()));
                    table.AddRow();
                }
            }
            string view = table.GetTable() + dataPage.PageToolBar;
            dataPage.Dispose();
            dataPage = null;
            //YXShop.BLL.Order.ShoppingCard bll = new YXShop.BLL.Order.ShoppingCard();
            //ChangeHope.WebPage.DataView view = new ChangeHope.WebPage.DataView();
            //view.RowHead = "&nbsp;/30px,商品名称/200px,购物数量/100px,购物时间/130px,其他参数/,预计金额/100px,操作/80px";
            //view.RowText = "{0}$@allnum,<a href='../product/productcontent.aspx?q_productid={1}' target='_blank'>{0}</a>$proName|id,Quantity,ShoppingDate,OtherParas,Payment,<a href='?id={0}' onclick=\"return confirm('是否删除该菜单!');\">删除</a>$id";
            this.ltlView.Text = view;
            view = null;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        private void Delete(int id)
        {
            YXShop.BLL.Order.ShoppingCard bll = new YXShop.BLL.Order.ShoppingCard();
            bll.Delete(id);
            bll = null;
        }
    }
}
